<h1>Actualités</h1>
<div class="cadreContenu">
<?php
	require_once ('../connexion.php');
	$actusNeeded=$_POST['actus'];

	if ($actusNeeded=="all"){
		try{
			$sql1='SELECT * FROM actus ORDER BY dateCreation DESC';
			$select = $connection->prepare($sql1, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$select->execute();
			while( $enregistrement = $select->fetch(PDO::FETCH_OBJ) )
			{
				$sql2='SELECT * FROM images WHERE id=:idImages';
				$select2 = $connection->prepare($sql2, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select2->execute(array(':idImages' => $enregistrement->idImages));
				$enregistrement2 = $select2->fetch(PDO::FETCH_OBJ);
				?>
						<h1><?php echo $enregistrement->titre;?></h1>
						<?php if($enregistrement2==true){?>
						<div class="imgCenter" >
							<div class="imgCenter2"><img id="imgBIG" src="images/<?php echo $enregistrement2->chemin;?>"/></div></div>
						<?php }?>
						<p><?php echo $enregistrement->contenu;?></p>
						<hr class="hrInfos"/>
				<?php
			}
		}catch(Exception $e){
			echo "<h3 class='error'>Impossible de charger les actualités</h3>";
		}
	}else{
		try{
			$sql1='SELECT * FROM actus WHERE id=:actus';
			$select = $connection->prepare($sql1, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
			$select->execute(array(':actus' => $actusNeeded));
			$enregistrement = $select->fetch(PDO::FETCH_OBJ);	
			if($enregistrement==true){
				$sql2='SELECT * FROM images WHERE id=:idImages';
				$select2 = $connection->prepare($sql2, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
				$select2->execute(array(':idImages' => $enregistrement->idImages));
				$enregistrement2 = $select2->fetch(PDO::FETCH_OBJ);			
				?>
						<h1><?php echo $enregistrement->titre;?></h1>
						<?php if($enregistrement2==true){?>
						<div class="imgCenter" >
							<div class="imgCenter2"><img id="imgBIG" src="images/<?php echo $enregistrement2->chemin;?>"/></div></div>
						<?php }?>
						<p><?php echo $enregistrement->contenu;?></p>
				<?php
			}
		}catch(Exception $e){
			echo "<h3 class='error'>Impossible de charger l'actualité</h3>";
		}
	}
?>
</div>